class RequestController < ApplicationController
  
  def accept
    friend_request = Request.find(params[:id])
    follow = Follower.new
    follow.user_id = friend_request.requester_id
    follow.follower_id = friend_request.user_id
    follow.follow_since = Time.now
    
    name = get_requester_name(friend_request.requester_id)
    
    if friend_request.destroy && follow.save
      flash[:notice] = "You've accepted #{name}'s friend request."
    else
      flash[:notice] = "Failed to accept friend request from #{name}."
    end
    redirect_to({:controller => :home, :action => "index"})
  end
  
  def ignore
    friend_request = Request.find(params[:id])
    name = get_requester_name(friend_request.requester_id)
    if friend_request.destroy
      flash[:notice] = "You've ignored #{name}'s friend request."
    else
      flash[:notice] = "Failed to ignore friend request from #{name}."
    end
    redirect_to({:controller => :home, :action => "index"})
  end
  
  private
  
  def get_requester_name(id)
    User.find(id).display_name
  end
  
  
end
